const Service = require("egg").Service

//const UserModel = require("./model")

class SongService extends Service {
  // 需要联表查询这首歌对应的用户信息
  async getList(page,pageSize){
    let start = parseInt((page-1)*pageSize)
    let sql = `SELECT song.* ,user.coverPictureUrl as userPic,
    user.musicCount,user.musicPlayCount,user.nickname,user.type 
    FROM song INNER JOIN user ON song.userId = user.id
    limit ? , ?`
    let data = await this.app.mysql.query(sql,[start,pageSize])

    return data
  }
  async getInfo(id){
    let sql = `SELECT song.* ,user.coverPictureUrl as userPic,
    user.musicCount ,user.musicPlayCount,user.nickname,user.type 
    FROM song INNER JOIN user ON song.userId = user.id
    where song.id = ?`
    let data = await this.app.mysql.query(sql,[id])

    if(!data){
      throw new Error("歌曲信息不存在")
    }
    return data
  }
}

module.exports = SongService
